package com.jeff.practice;

import java.util.Scanner;

/**
 * 字母坐标系, 给定两个字符串A和B, 计算A和B之间的最短距离。
 * @author yaojianfeng
 */
public class Test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] strings = in.nextLine().split(" ");
        String A = strings[0];
        String B = strings[1];
        System.out.println(shortestDistance(A, B));

    }

    public static int shortestDistance(String A, String B) {
        String M = "A" + A;
        String N = "A" + B;
        int m = M.length();
        int n = N.length();
        //x轴坐标对应的字母
        char[] ma = M.toCharArray();
        //y轴坐标对应的字母
        char[] nb = N.toCharArray();
        //构建一个二维数组,记录每个点的坐标信息
        Point[][] points = new Point[m][n];

        //i,j 是横纵轴坐标
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                Point point = new Point(new LocationInfo(i, ma[i]), new LocationInfo(j, nb[j]));
                points[i][j] = point;
            }
        }

        int[][] distance = new int[m][n];

        //遍历points数组,计算原点到每个点的距离
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) {
                    distance[i][j] = 0;
                } else if (i == 0) {
                    distance[i][j] = distance[i][j - 1] + 1;
                } else if (j == 0) {
                    distance[i][j] = distance[i - 1][j] + 1;
                } else {
                    boolean hypotenuse = isHypotenuse(points[i][j]);
                    if (hypotenuse) {
                        distance[i][j] = distance[i - 1][j - 1] + 1;
                        continue;
                    }
                    int left = distance[i - 1][j] + 1;
                    int top = distance[i][j - 1] + 1;
                    int min = Math.min(top, left);
                    distance[i][j] = min;
                }
            }
        }
        return distance[m - 1][n - 1];
    }

    static boolean isHypotenuse(Point p) {
        return p.x.locationCharacter.equals(p.y.locationCharacter);
    }


    static class Point {
        LocationInfo x; //横轴对应的坐标信息
        LocationInfo y;  //纵轴对应的坐标信息

        Point(LocationInfo x, LocationInfo y) {
            this.x = x;
            this.y = y;
        }
    }

    static class LocationInfo {
        int locationValue; //坐标值
        Character locationCharacter; //坐标对应的字母

        public LocationInfo(int locationValue, Character locationCharacter) {
            this.locationValue = locationValue;
            this.locationCharacter = locationCharacter;
        }
    }
}
